package com.flash.InventoryManagement.controller;

import com.flash.BusinessParameters.entity.Security;
import com.flash.GlobalManagement.util.Dbutil;
import com.flash.GlobalManagement.util.TableIdUtil;
import com.flash.GlobalManagement.util.TableNameUtil;
import com.flash.GlobalManagement.util.TableTimeUtil;
import com.flash.InventoryManagement.entity.SecurityStock;
import com.flash.InventoryManagement.mapper.SecurityStockMapper;
import com.flash.InventoryManagement.service.SecurityStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.sound.midi.Soundbank;
import java.sql.SQLOutput;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jr
 * @version 1.0
 * @date 2022/8/10
 */
@Controller
public class SecurityStockContrller {
    @Resource
    SecurityStockService securityStockService;

    @Resource
    Dbutil dbutil;

    @RequestMapping("secuityStockSelect")
    @ResponseBody
    public Map secuityStockSelect(SecurityStock securityStock, int page,int limit){

        Map map = new HashMap();
        List secuityStocklist = securityStockService.selectSecurityStock(securityStock,page,limit);
        //记录总条数
        int count =securityStockService.countSecurityStock();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",secuityStocklist);
        return map;
    }





    @RequestMapping("inestSecurityStock")
    @ResponseBody
    public String inestSecurityStock(SecurityStock securityStock){
        System.out.println("这是增加证券库存");
        securityStock.setSecurityStockId(dbutil.getMaxId3(TableIdUtil.SSID,TableNameUtil.SS,TableTimeUtil.SSTime,securityStock.getDatestock()));
        int i = securityStockService.insertSecurityStock(securityStock);
        System.out.println(i);
        if (i>0){
            return "增加成功";
        }else {
            return "增加失败";
        }
    }
    @RequestMapping("deleteSecurityStocks")
    @ResponseBody
    public String deleteSecurityStock(SecurityStock securityStock){
        System.out.println("这是删除证券库存");
        int i = securityStockService.deleteSecurityStock(securityStock);
        System.out.println(i);
        if (i>0){
            return "删除成功";
        }else {
            return "删除失败";
        }
    }

    @RequestMapping("updateSecurityStocks")
    @ResponseBody
    public String updateSecurityStocks(SecurityStock securityStock){
        System.out.println("这是修改证券库存");
        int i = securityStockService.updateSecurityStock(securityStock);
        System.out.println(i);
        if (i>0){
            return  "修改修改成功";
        }else {
            return "修改失败";
        }
    }
}
